<template>
	<view class="full-page flex flex-col root-style">
		<StepGroupTest v-if="WordList.length>0" :reviewles="ReviewUUID==''?LessonUUID:ReviewUUID" :isreview="1"
			err-learn class="content" timer-bar-sty="top:0" :show-timer="true" @module-event="moduleEvent" />
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		ktlapi,
		ktluser,
		OT,
		dateFormat
	} from '@/utils/index.js'
	import {
		useStudyStore
	} from '@/store/study';
	import StepGroupTest from "@/pages-study/study/modules/step-group-test"

	const WordList = ref([]);
	const studyStore = useStudyStore();

	const LessonUUID = ref("");
	const ReviewUUID = ref("");
	const SentenceId = ref(0);
	let ReviewTimer = "";

	onLoad(query => {
		LessonUUID.value = query.uuid;
		ReviewUUID.value = query.reviewles;
		ReviewTimer = query.reviewtimer;
		if (query.SentceId) {
			SentenceId.value = query.SentceId;
		}
		// console.log(SentenceId.value)
		// console.log("query",query);
	})

	function moduleEvent({
		action,
		payload
	}) {
		if (action === 'next') {
			// console.log(WordList.value);
			uni.navigateBack();
		}
	}

	function LoadReviewWords() {
		uni.showLoading({
			title: '加载中'
		});
		ktlapi({
			apiurl: OT.CommandSet,
			action: "Cus_AbsReviewLesson_V2",
			data: {
				LessonUUID: LessonUUID.value,
				SentenceId: SentenceId.value,
				ReviewTimer
			}
		}).then(res => {
			WordList.value = res.data.tables[0].table;

			if (WordList.value.length === 0) {
				uni.showModal({
					content: '本节课的词汇已经复习完毕',
					showCancel: false,
					success(res) {
						uni.navigateBack();
					}
				})
				return
			}

			var shuffleWords = res.data.tables[1].table;
			//console.log(WordList.value);
			for (var i = 0; i < WordList.value.length; i++) {
				WordList.value[i]["NeedRemeber"] = true;
				WordList.value[i]["SentenceSnapshot"] = JSON.parse(WordList.value[i]["SentenceSnapshot"])
				WordList.value[i]["Methods"] = JSON.parse(WordList.value[i]["Methods"])
			}

			studyStore.setWordGroup(WordList.value);
			studyStore.setShuffleWords(shuffleWords);
			uni.hideLoading();
		});
	}

	onShow(() => {
		//console.log('show'); 
		LoadReviewWords();
	})
</script>

<style scoped>
	.full-page {
		/* #ifdef H5 */
		height: calc(100vh - 44px) !important;
		/* #endif */
		overflow: hidden;
	}
</style>